package me.leiusual.sharing.ui.shop.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import me.leiusual.sharing.R
import me.leiusual.sharing.api.model.BusinessType

/**
 * author: leiusual
 * create on: 2019-07-30
 * description:
 */
class ShopBusinessAdapter(
    private val clickListener: (BusinessType) -> Unit
) : RecyclerView.Adapter<ShopBusinessViewHolder>() {

  private val dataSet = mutableListOf<BusinessType>()

  override fun getItemCount(): Int {
    return dataSet.size
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShopBusinessViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val itemView = inflater.inflate(R.layout.view_holder_shop_business, parent, false)
    return ShopBusinessViewHolder(itemView, clickListener)
  }

  override fun onBindViewHolder(holder: ShopBusinessViewHolder, position: Int) {
    holder.bind(dataSet[position])
  }

  fun submitList(list: List<BusinessType>) {
    dataSet.clear()
    dataSet.addAll(list)
    notifyDataSetChanged()
  }
}